﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FESSC_WORKBENCH
{
    class DateFunc
    {
        static public int GetAddDays(int year)
        {
            DateTime firstday = new DateTime(year, 1, 1);
            if (firstday.DayOfWeek != DayOfWeek.Monday) return (7 + Convert.ToInt32(firstday.DayOfWeek) - 1) % 7;
            else return 0;
        }

        static public int GetMaxWeek(int year)
        {
            DateTime lastday = new DateTime(year, 12, 31);
            int adddays = GetAddDays(year);
            if (adddays == 0) return (lastday.DayOfYear + GetAddDays(year)) / 7;
            else return (lastday.DayOfYear + GetAddDays(year)) / 7;
        }

        static public int GetWeek(DateTime date)
        {
            return (date.DayOfYear - 1 + GetAddDays(date.Year)) / 7 + 1;
        }

        static public DateTime GetDate(int year, int weekindex)
        {
            DateTime dt = new DateTime(year, 1, 1);
            dt = dt.AddDays((weekindex - 1) * 7 - GetAddDays(year));
            return dt;
        }
    }
}
